/*
 * Copyright (C) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IMAGE_KNIFE_C_KEKE_IMAGEKNIFE_TYPE_H
#define IMAGE_KNIFE_C_KEKE_IMAGEKNIFE_TYPE_H

#include <string>
namespace ImageKnifeC {

// 加载请求的类型 
enum class ImageRequestType {
    // 主图
    MAIN_SRC = 0,
    // 占位图
    PLACE_SRC,
    // 错误图
    ERROR_SRC
};

// 图片文件格式
enum class ImageFormat {
    UNKNOWN = 0,
    JPG,
    PNG,
    WEBP,
    BMP,
    GIF,
    SVG,
    TIFF,
    HEIC,
    ICO,
};

enum DataType: unsigned int {
    UNDEFINED = 1,
    STRING = 1 << 1,
    NUMBER = 1 << 2,
    PIXELMAP = 1 << 3,
    RESOURCE = 1 << 4,
};

enum CacheStrategy {
    // 默认-写入/读取内存和文件缓存
    DEFAULT = 0,
    // 内存相关信息
    MEMORY = 1,
    // 文件相关信息
    CACHE_FILE = 2
};

enum class CacheTaskType {
    // 非缓存器任务
    NONE = 0,
    // 写缓存任务
    WRITE,
    // 读缓存任务
    READ
};

struct ErrorInfo {
    std::string phase; // 图片加载阶段信息，如：网络加载阶段，缓存获取阶段及其解码阶段等
    int code;
};

struct DecodeImageInfo {
    // 解码后图片宽度
    int contentWidth = 0;
    // 解码后图片高度
    int contentHeight = 0;
};

// ImageKnifeOption.OnComplete 入参类型
struct EventImage {
    int32_t loadingStatus;
    float width;
    float height;
    float componentWidth;
    float componentHeight;
    float contentOffsetX;
    float contentOffsetY;
    float contentWidth;
    float contentHeight;
};

struct TimeInfo {
    uint64_t executeTime = 0;
    uint64_t requestStartTime = 0;
    uint64_t requestEndTime = 0;
    uint64_t requestCancelTime = 0;
    uint64_t memoryCheckStartTime = 0;
    uint64_t memoryCheckEndTime = 0;
    uint64_t diskCheckStartTime = 0;
    uint64_t diskCheckEndTime = 0;
    uint64_t netRequestStartTime = 0;
    uint64_t netRequestEndTime = 0;
    uint64_t decodeStartTime = 0;
    uint64_t decodeEndTime = 0;
};

// 映射ArkTs侧Resource资源
struct Resource {
    std::string bundleName;
    std::string moduleName;
    int id;
    int number = 0;
    std::string params;
};

struct ImageInfo {
    uint32_t imageWidth = 0;
    // 图片原始高度
    uint32_t imageHeight = 0;
    // 图片字节数
    uint32_t bufSize = 0;
    uint32_t httpCode = 0;
    TimeInfo timeInfo;
    ErrorInfo errorInfo;
    std::string type = "UNKNOWN";
    std::vector<std::vector<uint32_t>> decodeImages;
};

struct OnLoadCallBack {
    std::function<void(ImageInfo imageInfo)> onLoadStart = nullptr;
    std::function<void(ImageInfo imageInfo)> onLoadSuccess = nullptr;
    std::function<void(std::string error, ImageInfo imageInfo)> onLoadFailed = nullptr;
    std::function<void(std::string reason, ImageInfo imageInfo)> onLoadCancel = nullptr;
    virtual ~OnLoadCallBack() = default;
};

}

#endif //IMAGE_KNIFE_C_KEKE_IMAGEKNIFE_TYPE_H
